%clear_classes;
number_of_nodes = 40;
maximum_link_length_allowed = 800;
top = Topology(number_of_nodes, maximum_link_length_allowed);

src = 0;
dest = 0;

for i=1:number_of_nodes
    for j=1:number_of_nodes
        if (i~=j)&&(top.nodes(i).distance_vector(j) ~=inf)&&(top.nodes(i).distance_vector(j) ~=0)
            src = i;
            dest = j;
        end
    end
end

if src == 0
    error('no link found');
end

id = 555;
packet_size = 1000;
src_node = top.hap_nodes(src);
dest_node = top.hap_nodes(dest);
pack = Packet(id, packet_size, src_node, dest_node, []);

MessagesPrinter.instance().write_message('routing from source %d to dest %d\r\n', src, dest);

source_data_rate = 1000;
packets_gen = CBRPacketGenerator(pack, source_data_rate);

tick_counts = 100;
for j=1:tick_counts
    ck = ClockSingleton.instance();
     ck.tick();
end

packets_manager = PacketsManager.instance();
delivered_packets = packets_manager.delivered_packets;

for i=1:length(delivered_packets)
    packet = delivered_packets(i);
    MessagesPrinter.instance().write_message('source node: %d.  dest node: %d. route length: %d\r\n',packet.src_node.id,packet.dest_node.id,length(packet.route));
    packet_route = packet.route;
    for j=1:length(packet_route);
        if j~=length(packet_route)
            MessagesPrinter.instance().write_message('%d =>',packet_route(j));
        else
            MessagesPrinter.instance().write_message('%d\r\n',packet_route(j));
        end
    end
end

delivery_ratio = packets_manager.calc_delivery_rate();
MessagesPrinter.instance().write_message('delivery ratio %f\r\n',delivery_ratio);
